package edu.ynmd.helloworld.action;

import edu.ynmd.helloworld.vo.BMIForm;
import edu.ynmd.helloworld.vo.Result;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class PublicAction {

    @GetMapping("hello")
    public String hello() throws Exception{

        return "Hello World";



    }


    @PostMapping("/getBMIValue")
    public Result getBimValue(@RequestBody BMIForm bmiForm) throws Exception{

        float result = bmiForm.getTz()/(bmiForm.getSg()*bmiForm.getSg());
        String resultstr="";

        if (result<18.4){
            resultstr = "偏瘦";
        }
        else if (result>=18.5&&result<=23.9){
            resultstr = "正常";
        }
        else if (result>=24&&result<=27.9){
            resultstr ="过重";
        }
        else
        {
            resultstr = "肥胖";
        }
        Result r=new Result();
        r.setBmivalue(result);
        r.setResult(resultstr);

        switch (resultstr){
            case "偏瘦":
                r.setSuggest("多吃点");
                break;
            case "正常":
                r.setSuggest("别多吃，也别少吃");
                break;
            case "过重":
                r.setSuggest("少吃点");
                break;
            case "肥胖":
                r.setSuggest("别吃啦");
                break;




        }


        return r;
    }




}
